package org.lmw.mm.ctrl;

import java.util.HashMap;

import org.lmw.mm.app.AppConfig;
import org.lmw.mm.dao.User;

public class UserCtrl extends BaseCtrl{
  public void index(){
    render("/comm/login.html");
}

//登录
public void login(){
    String appid=AppConfig.APPID;
    User u=User.dao.findBynp(getPara("phone"), getPara("pwd"));
    if(null!=u){
        String cookie = u.getStr("phone") +appid+ u.getStr("pwd");
        setCookie(appid, cookie, 3600*24*30);
        setSessionAttr("sessionUser", u);
        setSessionAttr("sUname", u.getStr("phone"));
        redirect("/");
    }else{
        redirect("/");
    }
}


//注册
public void reg(){

}

//注销
public void logout(){
    removeSessionAttr("sessionUser");
    removeSessionAttr("sUname");
    removeCookie(AppConfig.APPID);
    redirect("/");
}


/**-----------------mobile ----------------*/

//登录
public void m_login(){
  User u=User.dao.findBynp(getPara("phone"), getPara("pwd"));
  res=new HashMap<String, Object>();
  if(null!=u){
     res.put("res_code", success_code);
     res.put("objStr", u);
  }else{
    res.put("res_code", error_code);
    res.put("objStr", "");
  }
  renderJson(res);
}


}
